package com.jsd.jmm;

import java.util.concurrent.TimeUnit;

/**
 * JMM 内存模型
 */
public class JMMDemo {

    static volatile int num = 0;

    public static void main(String[] args) {

        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "执行中，当前num=" + num);
            while (num == 0) {
                num++;
            }
            System.out.println(Thread.currentThread().getName() + "执行中，当前num=" + num);
        }).start();

        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        num = 1;
        System.out.println(num);

    }

}
